//
//  AiTabBarViewController.m
//  ROSE
//
//  Created by 艾阳 on 2018/5/22.
//  Copyright © 2018年 HeNanZhongDunYunAn. All rights reserved.
//

#import "AiTabBarViewController.h"
#import "AiNavigationViewController.h"
#import "MainViewController.h"
#import "RoseMarketViewController.h"
#import "UserCenterViewController.h"

@interface AiTabBarViewController ()<UITabBarControllerDelegate>

@end

@implementation AiTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addChildViewControllers];
    [self addChildTabBarItems];
    self.delegate = self;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)addChildViewControllers{
    AiNavigationViewController *mainNav =
        [[AiNavigationViewController alloc]initWithRootViewController:[[MainViewController alloc]init]];
    AiNavigationViewController *roseMarketNav = [[AiNavigationViewController alloc]initWithRootViewController:[[RoseMarketViewController alloc]init]];
    AiNavigationViewController *userCenterNav = [[AiNavigationViewController alloc]initWithRootViewController:[[UserCenterViewController alloc]init]];
    self.viewControllers = @[mainNav,roseMarketNav,userCenterNav];
    
    
}

- (void)addChildTabBarItems{
    NSDictionary *firstTabBarItemsAttributes = @{
                                                 @"TabBarItemTitle" : @"首页",
                                                 @"TabBarItemImage" : @"首页",
                                                 @"TabBarItemSelectedImage" : @"首页_selected",
                                                 };
    NSDictionary *secondTabBarItemsAttributes = @{
                                                  @"TabBarItemTitle" : @"玫瑰花园",
                                                  @"TabBarItemImage" : @"玫瑰花",
                                                  @"TabBarItemSelectedImage" : @"玫瑰花_selected",
                                                  };
    NSDictionary *thirdTabBarItemsAttributes = @{
                                                 @"TabBarItemTitle" : @"我的",
                                                 @"TabBarItemImage" : @"个人中心",
                                                 @"TabBarItemSelectedImage" : @"个人中心_selected",
                                                 };
    NSArray<NSDictionary *> *tabBarItemsAttributes = @[firstTabBarItemsAttributes,secondTabBarItemsAttributes,thirdTabBarItemsAttributes];
    [self.childViewControllers enumerateObjectsUsingBlock:^(__kindof UIViewController * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        obj.tabBarItem.title = tabBarItemsAttributes[idx][@"TabBarItemTitle"];
        obj.tabBarItem.image = [UIImage imageNamed:tabBarItemsAttributes[idx][@"TabBarItemImage"]];
        obj.tabBarItem.selectedImage = [UIImage imageNamed:tabBarItemsAttributes[idx][@"TabBarItemSelectedImage"]];
        obj.tabBarItem.titlePositionAdjustment = UIOffsetMake(0, 0);
    }];
    
    self.tabBar.barTintColor = [UIColor colorWithRed:233/255.0 green:123/255.0 blue:155/255.0 alpha:1];
    self.tabBar.tintColor = [UIColor whiteColor];
}

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
    return YES;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
